<?php
namespace Apps\Back\Controllers;
use Apps\Back\Controllers\ControllerAuth;
use Apps\Model\User;
use Phalcon\Paginator\Adapter\Model as PaginatorModel;



class UserController extends ControllerAuth{

    public function indexAction($currentPage){
	      $row=User::find();
        //查询结果分页
        $paginator   = new PaginatorModel(
          array(
              "data"  => $row,
              "limit" => 6,
              "page"  => $currentPage
          )
        );
        $page = $paginator->getPaginate();
	      $this->view->setVar('page',$page);

    }


    public function searchAction(){
     	  $name=$this->request->getPost('name','string');
        $tel=$this->request->getPost('tel','string');
	     
	      if(empty($name) AND empty($tel)){
             $this->jump("admin/user/index","查询条件不能全为空");
            $this->view->disable();
        }
	      $result = User::find("name = '$name' or tel='$tel'");

	      if(empty($result)){
      	     echo "用户不存在";
      	     return;
	      }

	      $this->view->setVar('result',$result);
  
    }
    
    public function delAction($id){
        $row=User::findFirst("id=$id");
	      if(empty($row)){
	      	$this->jump("admin/User/index","用户不存在");
	      }
        if($row->delete()){
        	$this->jump("admin/User/index","删除成功");
        }
    }


}